<?php
/**
 * Created by PhpStorm.
 * User: andrei
 * Date: Jun 27, 2012
 * Time: 3:11:40 PM
 * To change this template use File | Settings | File Templates.
 */
 
class Db_Products_LayoutItems extends Common {
	protected static $tableName = TAB_LAYOUT_ITEMS;
	protected static $dbFields = array(
        'id',
		'li_owner_id',
		'li_owned_by',
		'li_type',
		'li_level',
		'li_rotation',
		'li_width',
		'li_height',
		'li_x',
		'li_y',
		'li_design_layer',
		'li_is_poem',
		'li_is_multi_value',
        'deleted'
	);


	/**
	 * @var Db_Products_LayoutItems
	 */
	public $objectArray;

	public $id;
	public $li_owner_id;
	public $li_owned_by;
	public $li_type;
	public $li_level;
	public $li_rotation;
	public $li_width;
	public $li_height;
	public $li_x;
	public $li_y;
	public $li_design_layer;
	public $li_is_poem;
	public $li_is_multi_value;
    public $deleted;

    function __construct($value=NULL, $fieldName=NULL) {
        parent::__construct($value, $fieldName);
    }

	public static function deleteByOwner($ownerId, $type) {
		if(!$ownerId || !$type) {
			return false;
		}
		return self::$DB->q("DELETE FROM ?f WHERE `li_owner_id` = ?d AND `li_owned_by` = ? ;", self::$tableName, $ownerId, $type);
	}

	public static function getIdsByOwnerId($ownerId, $type) {
		if(!$ownerId || !$type) {
			return false;
		}
		$result = self::$DB->q("SELECT `id` FROM ?f WHERE `li_owner_id` = ?d AND `li_owned_by` = ? ;", self::$tableName, $ownerId, $type);
		$dataReturn = array();
		while($data = $result->fetch_object()) {
			$dataReturn[] = $data->id;
		}
		return $dataReturn;
	}

}